import { _decorator, Component, Node, tween, v3 } from "cc";
import { back } from "./back";
const { ccclass, property } = _decorator;

@ccclass("j2")
export class j2 extends back {
  @property(Node)
  item1: Node = null;
  @property(Node)
  item2: Node = null;
  @property(Node)
  item3: Node = null;

  tempEulerAngles = v3();
  start() {
    // 旋转 angle 运动
    tween(this.item1).by(2, { angle: 50 }).repeatForever().start();

    // 旋转父节点
    tween(this.item3.parent).by(2, { angle: 50 }).repeatForever().start();
  }

  update(deltaTime: number) {
    // 用 update 的方式不断改变旋转度, 效果同 tween
    this.tempEulerAngles = this.item2.eulerAngles;
    this.tempEulerAngles.z += deltaTime * 25;
    this.item2.setRotationFromEuler(this.tempEulerAngles);
  }
}
